package com.wei800.turnover.config.druid;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
@Order(-100) 							// 优先执行
public class DataSourceAspect { 					// 基于Action实现
    @Before("execution(* com.wei800.turnover.mapper.vlaibao..*.*(..))") 		// 应用切面
    public void switchVlaibaoDataSource() {
        DynamicDataSource.setDataSource(
                DynamicDataSource.DataSourceNames.VLAIBAO_DATASOURCE); 	// 设置数据源标记
        log.info("数据源切换到“vlaibao”：{}", DynamicDataSource.getDataSource()); // 日志输出
    }
    @Before("execution(* com.wei800.turnover.mapper.vlaibao_dic..*.*(..))")  	// 应用切面
    public void switchVlaibao_dicDataSource() {
        DynamicDataSource.setDataSource(
                DynamicDataSource.DataSourceNames.VLAIBAO_DIC_DATASOURCE);  	// 设置数据源标记
        log.info("数据源切换到“vlaibao_dic”：{}", DynamicDataSource.getDataSource()); // 日志输出
    }
    @Before("execution(* com.wei800.turnover.mapper.vlaibao_dic..*.*(..))")  	// 应用切面
    public void switchVlaibao_websitetrafficDataSource() {
        DynamicDataSource.setDataSource(
                DynamicDataSource.DataSourceNames.VLAIBAO_WEBSITETRAFFIC_DATASOURCE);  	// 设置数据源标记
        log.info("数据源切换到“websitetraffic”：{}", DynamicDataSource.getDataSource()); // 日志输出
    }
}

